package com.zhenghaijin.animecontentservice.controller;

import com.zhenghaijin.animecontentservice.model.Anime;
import com.zhenghaijin.animecontentservice.service.AnimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// Add this import for logging
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RestController
@RequestMapping("/api/animes")
public class AnimeController {
    // Add this line to define the log variable
    private static final Logger log = LoggerFactory.getLogger(AnimeController.class);
    @Autowired
    private AnimeService animeService;

    @GetMapping
    public List<Anime> getAllAnimes() {
        return animeService.getAllAnimes();
    }

    @GetMapping("/{id}")
    public Anime getAnimeById(@PathVariable Long id) {
        return animeService.getAnimeById(id);
    }

    @PostMapping
    public void addAnime(@RequestBody Anime anime) {
        animeService.addAnime(anime);
        log.info("Added new anime: {}", anime.getTitle());
    }

    @PutMapping("/{id}")
    public void updateAnime(@PathVariable Long id, @RequestBody Anime anime) {
        anime.setId(id);
        animeService.updateAnime(anime);
    }

    @DeleteMapping("/{id}")
    public void deleteAnime(@PathVariable Long id) {
        animeService.deleteAnime(id);
    }
}
